//
//  BJHotListVC.m
//  jinwang
//
//  Created by jzb on 2018/3/16.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "BJHotListVC.h"
#import "BJDynamicSnapshotVC.h"
#import "BJDynamicLoveshotVC.h"
#import "BJDynamicGoodArticleVC.h"

@interface BJHotListVC ()

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;

@end

@implementation BJHotListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *list = @[@"快照",@"爱拍",@"佳文"];
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRM(0, 0, 750, 88) titles:list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
    //    _segHead.fontScale = 1.1;
    _segHead.fontSize = 16;
    _segHead.deSelectColor = kRGBColor(80, 80, 80);
    _segHead.selectColor = UIColorHex(0xEEA72B);
    _segHead.lineScale = .4;
    _segHead.bottomLineHeight = .5;
    _segHead.lineColor = UIColorHex(0xEEA72B);
    //    _segHead.headColor = [UIColor clearColor];
    _segHead.bottomLineColor = kRGBColor(230, 230, 230);
    
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRM(0, 88+40*2, 750, 1334-88-64*2-40*2) vcOrViews:[self vcArr:list.count]];
    
    _segScroll.loadAll = YES;
    _segScroll.showIndex = 0;
    
    //    _segScroll.backgroundColor = [UIColor purpleColor];
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        
        [self.view addSubview:_segHead];
        [self.view addSubview:_segScroll];
    }];
    
    [self DynamicTabbarBuild];

}
- (void)DynamicTabbarBuild{
    
    NSArray *BtnTitleArr = @[@"人气",@"点赞",@"礼物",@"热评",@"推荐"];
    
    UIView *TabbarView = [[UIView alloc]initWithFrame:CGRM(0, 88, 750, 80)];
    TabbarView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:TabbarView];
    UIView *TabbarViewLine = [[UIView alloc]initWithFrame:CGRM(0, 39.5*2, 750, 1)];
    TabbarViewLine.backgroundColor = kRGBColor(230, 230, 230);
    [TabbarView addSubview:TabbarViewLine];
    for (int i = 0; i < BtnTitleArr.count; i++) {
        UIButton *TabbarItem = [[UIButton alloc]initWithFrame:CGRM(750/5*i, 0, 750/5, 39.5*2)];
        //        TabbarItem.backgroundColor = [UIColor purpleColor];
        [TabbarItem setTitle:BtnTitleArr[i] forState:UIControlStateNormal];
        TabbarItem.titleLabel.font = [UIFont systemFontOfSize:16];
        [TabbarItem setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
        [TabbarItem addTarget:self action:@selector(TabbarItemOnclick:) forControlEvents:UIControlEventTouchUpInside];
        TabbarItem.tag = 1010 + i;
        if (i == 0) {
            [TabbarItem setTitleColor:UIColorHex(0xEEA72B) forState:UIControlStateNormal];
        }
        [TabbarView addSubview:TabbarItem];
    }

    
}
- (void)TabbarItemOnclick:(UIButton *)sender{
    
    UIButton *button01 = (UIButton *)[self.view viewWithTag:1010];
    UIButton *button02 = (UIButton *)[self.view viewWithTag:1011];
    UIButton *button03 = (UIButton *)[self.view viewWithTag:1012];
    UIButton *button04 = (UIButton *)[self.view viewWithTag:1013];
    UIButton *button05 = (UIButton *)[self.view viewWithTag:1014];
    
    [button01 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
    [button02 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
    [button03 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
    [button04 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
    [button05 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
    
    [sender setTitleColor:UIColorHex(0xEEA72B) forState:UIControlStateNormal];
    
    NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
    [dict setValue:[NSString stringWithFormat:@"%ld",sender.tag - 1010] forKey:@"post_order"];
    NSNotification *notification =[NSNotification notificationWithName:@"JWBJHotListNotification" object:nil userInfo:dict];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    
}


- (NSArray *)vcArr:(NSInteger)count {
    
    NSMutableArray *arr = [NSMutableArray array];
    BJDynamicSnapshotVC *Snapshot_VC = [[BJDynamicSnapshotVC alloc]init];
    BJDynamicLoveshotVC *Loveshot_VC = [[BJDynamicLoveshotVC alloc]init];
    BJDynamicGoodArticleVC *GoodArticle_VC = [[BJDynamicGoodArticleVC alloc]init];
    
    Snapshot_VC.VCType = 1;
    Loveshot_VC.VCType = 1;
    GoodArticle_VC.VCType = 1;
    
    [arr addObject:Snapshot_VC];
    [arr addObject:Loveshot_VC];
    [arr addObject:GoodArticle_VC];
    
    
    return arr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
